import request from '../../utils/request'
import { requestString } from '../../utils/request'
import Constants from '../../utils/Constants';

/**
 * 分页查询消息订阅
 *
 * @param isReady
 * @param status
 * @param page
 * @returns {Promise.<Object>}
 */
export async function queryMessages({ isReady, status, type, title, page }) {
    return request(apiPath.authcenter + "/api/msg", {
        method: 'GET',
        data: { isReady, status, type, title, page: page.page, size: page.size, appCode: Constants.APPCODE }
    });
}

/**
 * 查询消息详情
 *
 * @param id
 */
export async function getMsgById({ id }) {
    return request(apiPath.authcenter + "/api/msg/" + id, {
        method: 'GET',
    });
}

/**
 * 把消息置为已读
 *
 * @param id
 */
export async function updateMsgReady({ id }) {
    return request(apiPath.authcenter + "/api/msg/" + id + "/ready", {
        method: 'PUT',
    });
}

/**
 * 查看未读消息总数
 *
 * @param id
 */
export async function getUnReadCount() {
    return request(apiPath.authcenter + "/api/msg/unread/count", {
        method: 'GET',
        data: { appCode: Constants.APPCODE }
    });
}

/**
 * 查看未读消息总数
 *
 * @param id
 */
export async function deleteMsgById({ id }) {
    return request(apiPath.authcenter + "/api/msg/" + id, {
        method: 'DELETE',
    });
}

/**
 * 批量删除
 *
 * @param id
 */
export async function deleteMsgs({ ids }) {
    return requestString(apiPath.authcenter + "/api/msg", {
        method: 'DELETE',
        data: ids
    });
}